<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitStatPlatform extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('stats_platform', function (Blueprint $table) {
            $table->comment = '平台每日统计表';
            
            $table->increments('id');
            $table->uuid('uuid')->index() ;

            $table->date('day')->index()->comment('日期');

            $table->bigInteger('all_money')->unsigned()->default(0)->index()->comment('平台人民币余额');
            $table->bigInteger('all_score')->unsigned()->default(0)->index()->comment('平台积分余额');

            $table->integer('withdraw_money')->unsigned()->default(0)->index()->comment('当日成功提现');
            $table->integer('depot_money')->unsigned()->default(0)->index()->comment('当日在线充值');

            $table->integer('admin_out_money')->unsigned()->default(0)->index()->comment('管理后台增加的余额');
            $table->integer('admin_in_money')->unsigned()->default(0)->index()->comment('管理后台减少的余额');

            $table->integer('admin_out_score')->unsigned()->default(0)->index()->comment('管理后台增加的积分');
            $table->integer('admin_in_score')->unsigned()->default(0)->index()->comment('管理后台减少的积分');

            $table->integer('all_user')->unsigned()->default(0)->index()->comment('当日总用户数');
            $table->integer('active_user')->unsigned()->default(0)->index()->comment('当日活跃用户数');

            $table->integer('order_money')->unsigned()->default(0)->index()->comment('总订单金额');
            $table->integer('order_score')->unsigned()->default(0)->index()->comment('总订单积分');
            $table->integer('order_pay_money')->unsigned()->default(0)->index()->comment('总订单支付金额');

            $table->integer('all_package_money')->unsigned()->default(0)->index()->comment('总产出物品人民币');
            $table->integer('all_package_score')->unsigned()->default(0)->index()->comment('总产出物品积分');

            $table->softDeletes();
            $table->timestamps();

        });

        Schema::table('users', function (Blueprint $table) {
            
            $table->index('last_active_at');
            
        });

        Schema::table('withdraw_records', function (Blueprint $table) {
            
            $table->index('handled_at');
            
        });

        Schema::table('orders', function (Blueprint $table) {
            
            $table->index('money_paid_at');
            
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::disableForeignKeyConstraints();
        Schema::dropIfExists('stats_platform');
    }
}
